﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CalcLibrary.Interface;
using CalcLibrary.Model;

namespace CalcLibrary
{
    public class MainCalculator
    {
        #region Private Fields

        private IBasicCalculator _calculator;
        private CalcModel _data;
        
        #endregion

        #region Constructors
        
        public MainCalculator()
        {
            this._calculator = new BasicCalculator();
        }
        
        #endregion
        
        #region Properties
        
        public CalcModel Data
        {
            get { return _data; }
            set { _data = value; }
        }
        
        #endregion
        
        #region Methods
        
        public int Calculate()
        {
            int result = 0;
            if (this.Data != null)
            {
                if (this.Data.Mode == CalMode.Single)
                {
                    switch (this.Data.Operation)
                    {
                        case CalOperation.Add:
                            result = this._calculator.Add(this.Data.IntegerValue1, this.Data.IntegerValue2);
                            break;
                        case CalOperation.Sub:
                            result = this._calculator.Sub(this.Data.IntegerValue1, this.Data.IntegerValue2);
                            break;
                        case CalOperation.Mul:
                            result = this._calculator.Mul(this.Data.IntegerValue1, this.Data.IntegerValue2);
                            break;
                        case CalOperation.Div:
                            result = this._calculator.Div(this.Data.IntegerValue1, this.Data.IntegerValue2);
                            break;
                        //case CalOperation.AddList:
                        //    result = this._calculator.AddList(this.Data.ListOfIntegerValue);
                        //    break;
                    }
                }
                else
                {
                    //return result;
                    result = this._calculator.ComlexListOperation(this.Data.ListOfIntegerValue, this.Data.Operation);
                }
            }
            else
            {
                Console.WriteLine("There is no data to be calculated");
                //return 0;
            }
            return result;
        }
        #endregion
        
    }
    public enum CalOperation { Add, Mul, Sub, Div, AddList };
    public enum CalMode { Single, List};
}
